package com.study.module.datasource.config;

import com.study.module.datasource.enums.DataSourceType;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DynamicContextHolder {

    private static final ThreadLocal<DataSourceType> CONTEXT_HOLDER = new ThreadLocal<>();

    public static void set(DataSourceType type) {
        CONTEXT_HOLDER.set(type);
        log.debug("切换到数据源 {}", type);
    }

    public static DataSourceType get() {
        return CONTEXT_HOLDER.get();
    }

    public static void clear() {
        CONTEXT_HOLDER.remove();
    }

}